package com.ruoyi.jiajia.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JiajiaCancelConfig;
import com.ruoyi.system.service.IJiajiaCancelConfigService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 取消订单原因Controller
 * 
 * @author knd
 * @date 2021-11-04
 */
@Controller
@RequestMapping("/jiajia/cancelConfig")
public class JiajiaCancelConfigController extends BaseController
{
    private String prefix = "jiajia/cancelConfig";

    @Autowired
    private IJiajiaCancelConfigService jiajiaCancelConfigService;

    @RequiresPermissions("jiajia:cancelConfig:view")
    @GetMapping()
    public String cancelConfig()
    {
        return prefix + "/cancelConfig";
    }

    /**
     * 查询取消订单原因列表
     */
    @RequiresPermissions("jiajia:cancelConfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaCancelConfig jiajiaCancelConfig)
    {
        startPage();
        List<JiajiaCancelConfig> list = jiajiaCancelConfigService.selectJiajiaCancelConfigList(jiajiaCancelConfig);
        return getDataTable(list);
    }

    /**
     * 导出取消订单原因列表
     */
    @RequiresPermissions("jiajia:cancelConfig:export")
    @Log(title = "取消订单原因", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaCancelConfig jiajiaCancelConfig)
    {
        List<JiajiaCancelConfig> list = jiajiaCancelConfigService.selectJiajiaCancelConfigList(jiajiaCancelConfig);
        ExcelUtil<JiajiaCancelConfig> util = new ExcelUtil<JiajiaCancelConfig>(JiajiaCancelConfig.class);
        return util.exportExcel(list, "取消订单原因数据");
    }

    /**
     * 新增取消订单原因
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存取消订单原因
     */
    @RequiresPermissions("jiajia:cancelConfig:add")
    @Log(title = "取消订单原因", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaCancelConfig jiajiaCancelConfig)
    {
        return toAjax(jiajiaCancelConfigService.insertJiajiaCancelConfig(jiajiaCancelConfig));
    }

    /**
     * 修改取消订单原因
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaCancelConfig jiajiaCancelConfig = jiajiaCancelConfigService.selectJiajiaCancelConfigById(id);
        mmap.put("jiajiaCancelConfig", jiajiaCancelConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存取消订单原因
     */
    @RequiresPermissions("jiajia:cancelConfig:edit")
    @Log(title = "取消订单原因", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaCancelConfig jiajiaCancelConfig)
    {
        return toAjax(jiajiaCancelConfigService.updateJiajiaCancelConfig(jiajiaCancelConfig));
    }

    /**
     * 删除取消订单原因
     */
    @RequiresPermissions("jiajia:cancelConfig:remove")
    @Log(title = "取消订单原因", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaCancelConfigService.deleteJiajiaCancelConfigByIds(ids));
    }
}
